import { deleteTags, getAllTags, addTags, editTags } from "@/services/tagsService";
export default {
    namespaced: true,
    state: {
        tags: null,
    },
    mutations: {
        setTags(state, payload) {
            state.tags = payload
        },
    },
    actions: {
        //查询全部
        async fetchTagsDate(context,payload) {
            let {page,pagesize} = payload
            let res = await getAllTags(page,pagesize);
            context.commit("setTags", res.rows);
            return res
        },
        //删除
        async deleteTagsData(context, payload) {
            await deleteTags(payload);
        },
        //修改
        async editTagsData(context, payload) {
            console.log(payload);
            let { name, number, id } = payload
            await editTags(id, name, number);
        },
        //增加
        async addTagsData(context, payload) {
            let { name, number } = payload
            console.log(name, number);
            let res = await addTags(name, number);
            context.commit("setTags", res.rows)
        }
    }
}